﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PrimaryAlgorithm.SingleNumber
{
    class MainProject
    {
        static void Main(string[] args)
        {
            int[] nums = new int[] { 2, 2, 2 ,1};
            Console.WriteLine(SingleNumber(nums));
            Console.ReadKey();
        }
        public static int SingleNumber(int[] nums)
        {
            int reduce = 0;
            foreach (var item in nums)
            {
                reduce = reduce ^ item;
            }
            return reduce;


            //排序后查找
            //Array.Sort(nums);
            //int index = 0;
            //int recordNum = nums[0];
            //for (int i = 0; i < nums.Length; i++)
            //{
            //    if (nums[i] == recordNum)
            //    {
            //        index++;
            //    }
            //    else
            //    {
            //        if (index == 1 )
            //        {
            //            return nums[i - 1];
            //        }
            //        recordNum = nums[i];
            //        index = 1;
            //    }
            //}
            //if (index==1)
            //{
            //    return recordNum;
            //}
            //return 0;
        }
    }
}
